class_name Tail
extends Line2D


@export var player: Player
## 轨迹长度
@export var tail_length: int = 25
## 轨迹持续时间（秒）
@export var tail_duration: float = 1.0


var _points: Array[Vector2] = []
var _is_active: bool = false
var _tail_time: float



func start_tail():
	_is_active = true
	_tail_time = 0.0
	_clear_points()


func stop_tail():
	_is_active = false
	_clear_points()



func _process(delta: float):
	if not _is_active:
		return

	if _tail_time >= tail_duration:
		stop_tail()
		return
	_tail_time += delta

	_points.append(player.global_position)
	if _points.size() > tail_length:
		_points.pop_front()

	points = _points


func _clear_points():
	clear_points()
	_points.clear()
